package com.briup.cms.web.controller;

import com.briup.cms.bean.Category;
import com.briup.cms.service.ICategoryService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资讯栏目相关接口
 **/
@Api(tags="资讯栏目相关接口")
@RestController
@RequestMapping("/auth/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;


    @ApiOperation(value = "分页查询所有资讯分类",notes = "包含所以一级栏目和二级栏目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
    })
    @GetMapping("/page/queryAll")
    public Message pageQueryAll(int pageNum,int pageSize){
        PageInfo<Category> data = categoryService.pageQueryAll(pageNum,pageSize);
        return MessageUtil.success(data);
    }
    @ApiOperation(value = "查询所有栏目",notes = "不分页")
    @GetMapping("/find/all")
    public Message findAll(){
        List<Category> list = categoryService.findAll();
        return MessageUtil.success(list);
    }


    @ApiOperation(value = "通过id删除栏目")
    @DeleteMapping("/deleteById")
    public Message deleteById(int id){
        categoryService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "批量删除栏目")
    @DeleteMapping("/batchDelete")
    public Message batchDelete(int[] ids){
        categoryService.batchDelete(ids);
        return MessageUtil.success("删除成功");
    }


    @ApiOperation(value = "保存栏目信息")
    @PostMapping("/save")
    public Message saveCategory(Category category){
        categoryService.saveCategory(category);
        return MessageUtil.success("保存栏目成功");
    }

    @ApiOperation(value = "更新栏目信息")
    @PutMapping("/update")
    public Message updateCategory(Category category){
        categoryService.updateCategory(category);
        return MessageUtil.success("更新栏目成功");
    }




}
